﻿using BCT.Models;
using BCT.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BCT.Domains
{
    public class UserManageDomain : IUserManageDomain
    {
        private readonly IUserManageRepository _userManageRepository;

        public UserManageDomain(UserManageRepository userManageRepository)
        {
            _userManageRepository = userManageRepository;
        }
        //获取用户列表
        public DataListModel<UserModel> GetUserList(ConditionModel model)
        {
            var userlist = _userManageRepository.GetUserList(model.UserName,model.RoleId);
            //检索时的bug
            //while(Count <= (model.Page - 1) * model.Limit){
            //    model.Page--;
            //}
            var result = new DataListModel<UserModel>()
            {
                Count = userlist.Count(),
                Data = userlist.Skip((model.Page - 1) * model.Limit).Take(model.Limit).ToList(),
            };
            return result;
        }
          


        //修改用户
        public string ModefyUser(UserModel model)
        {
            return _userManageRepository.ModefyUser(model);
        }
        
        //获取所有用户的Power种类
        //public List<int?> GetPowerList()
        //{
        //    return _userManageRepository.GetPowerList();
        //}

        //增加用户
        public bool AddUser(UserModel model)
        {
            return _userManageRepository.AddUser(model);
        }

        //对用户进行逻辑删除（禁用或启用）
        public string LogDelete(UserModel model)
        {
            return _userManageRepository.LogDelete(model);
        }
    }
}
